<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>用户管理</title>
	<link rel="stylesheet" href="../EasyUI-1.5.3/themes/default/easyui.css">
    <link rel="stylesheet" href="../css/icon.css">
    <link rel="stylesheet" href="../css/index.css">
    <script src="../js/jquery-1.8.0.min.js"></script>
    <script src="../EasyUI-1.5.3/jquery.min.js"></script>
    <script src="../EasyUI-1.5.3/jquery.easyui.min.js" ></script>
    <script src="../EasyUI-1.5.3/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../js/jquery.serializejson.min.js"></script>
    <script src="../js/xheditor/xheditor-1.2.2.min.js" charset="utf-8"></script>
	<script src="../js/xheditor/xheditor_lang/zh-cn.js" charset="utf-8"></script>
</head>
<body>
	<div class="easyui-layout" data-options="fit:true">
	    <!-- Begin of toolbar -->
	    <div id="wu-toolbar-2">
	        <div class="wu-toolbar-button">
	            <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="openAdd()" plain="true">添加</a>
	            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="openEdit()" plain="true">修改</a>
	            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="remove()" plain="true">删除</a>
	            <a href="#" class="easyui-linkbutton" iconCls="icon-reload" onclick="reload()" plain="true">刷新</a>
	        </div>
	    </div>
	    <div class="easyui-panel" title="新闻编辑" style="width:100%;height:100%;padding:30px 70px 50px 70px">
   		<form method="post" id="news-form-content" data-options="novalidate:true">

			<div style="margin-bottom:10px">
				<div>Title</div>
				<input id="news-form-title" class="easyui-textbox" name="title" style="width:100%">
			</div>
			<div style="margin-bottom:10px">
				<div>Author</div>
				<input id="news-form-author" class="easyui-textbox" name="author" style="width:100%">
			</div>
			<div style="margin-bottom:10px">
				<div>alther-title</div>
				<input class="easyui-textbox" name="other_title" style="width:100%">
			</div>
			<div style="margin-bottom:10px">
				<div>Classify</div>
				<input id="news-form-classify" class="easyui-combobox" name="classifyID"
    data-options="valueField:'_id',textField:'text',value:'nodejs',url:'http://localhost:3000/cate/list',method:'get'">
			</div>
			<div style="margin-bottom:10px">
				<div>分类标签</div>
					<label><input name="tips" type="checkbox" value="" />极客 </label>
					<label><input name="tips" type="checkbox" value="" />GitHub </label>
					<label><input name="tips" type="checkbox" value="" />banner </label>
					<label><input name="tips" type="checkbox" value="" />pire </label>
				</div>
			<div style="margin-bottom:10px">
				<div>发布时间</div>
				<input class="easyui-datetimebox" name="date"
    data-options="required:true,showSeconds:false" value="3/4/2010 2:3" style="width:100%">
			</div>
			<div style="margin-bottom:10px">
				<div>Content</div>
				<textarea id="content"  name="content" cols="155" rows="20" style="resize:none"></textarea>
			</div>
			<div style="text-align:center;padding:5px">
	    		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitNews()">提交</a>
	    		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitOLd()">修改</a>
	    		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearNews()">清除</a>
	   		</div>
		</form>
		</div>
	</div>
	
	<script type="text/javascript">
		//载入页面时候判断是否读取
		var items =  (window.location.search).substr(1);
		(function(){
			if(items){
				console.log(1);
				console.log(items);
				$.ajax({
					url:'http://localhost:3000/content/listtoo/'+items,
					type:'POST',
					success:function(data){
						console.log(data);
						if(data){
							$("#news-form-content").form('load',data);
						}
						else
						{
							$.messager.alert('信息提示','异常操作！','info');
						}
					}
				});
			}else{
			}
		})()

		//富文本编辑器
		$(pageInit);
		function pageInit()
		{
			// $.extend(XHEDITOR.settings,{shortcuts:{'ctrl+enter':submitForm}});
			$('#content').xheditor({
				html5Upload:false,
				upMultiple:'1',

				upLinkUrl:"/uploadImg",
				upLinkExt:"zip,rar,txt",

				upImgUrl:"/uploadImg",
				upImgExt:"jpg,jpeg,gif,png",

				upFlashUrl:"upload.php",
				upFlashExt:"swf",

				upMediaUrl:"upload.php",
				upMediaExt:"wmv,avi,wma,mp3,mid"
			});
		}

		//单击将数据存储在后台
		function submitNews(){

			let newstitle = $('#news-form-title');
			let newsauthor = $('#news-form-author');
			let newsclassify = $('#news-form-classify');
			let newscontent = $('#content');
			console.log($('#news-form-content').serializeJSON())
			$('#news-form-content').form('submit', {
				// url:'http://localhost:3000/content/data',
				onSubmit:()=>{
					//这里做一些检测和判断
					if(newstitle.val() == '' || newsauthor.val() == '' || newsclassify.val() =="" || newscontent.val() == ''){
						$.messager.alert('信息提示','不能为空！','info');
						return false;
					}
				},
				success:()=>{
					$.ajax({
						url:'http://localhost:3000/content/data',
						type:'POST',
						data:$('#news-form-content').serializeJSON(),
						success:function(data){
							console.log(data);
							if(data){
								$.messager.alert('信息提示','添加成功！','info',()=>{
									clearNews();
								});
								// $('#wu-dialog-2').dialog('close');
							}
							else
							{
								$.messager.alert('信息提示','添加失败！','info');
							}
						}
					});
				}
			});
		}
		//修改跟新按钮
		function submitOLd(){
			let newstitle = $('#news-form-title');
			let newsauthor = $('#news-form-author');
			let newsclassify = $('#news-form-classify');
			let newscontent = $('#content');
			console.log($('#news-form-content').serializeJSON())
			$('#news-form-content').form('submit', {
				// url:'http://localhost:3000/content/data',
				onSubmit:()=>{
					//这里做一些检测和判断
					if(newstitle.val() == '' || newsauthor.val() == '' || newsclassify.val() =="" || newscontent.val() == ''){
						$.messager.alert('信息提示','不能为空！','info');
						return false;
					}
				},
				success:()=>{
					$.ajax({
						url:'http://localhost:3000/content/data/'+items,
						type:'POST',
						data:$('#news-form-content').serializeJSON(),
						success:function(data){
							console.log(data);
							if(data){
								$.messager.alert('信息提示','更新成功！','info',()=>{
									clearNews();
								});
								// $('#wu-dialog-2').dialog('close');
							}
							else
							{
								$.messager.alert('信息提示','更新失败！','info');
							}
						}
					});
				}
			});
		}
		//清空表单
		function clearNews(){
			$('#news-form-content').form('clear');
			$('#content').val("");
		}
	</script>
    <script type="text/javascript" src="../js/changeTable.js"></script>
</body>
</html>